package zhibi.wechat.mp.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import zhibi.frame.domain.Page;
import zhibi.frame.mybatis.example.Example;
import zhibi.frame.mybatis.example.ExampleType;
import zhibi.wechat.mp.domain.User;
import zhibi.wechat.mp.extra.base.BaseController;
import zhibi.wechat.mp.service.UserService;

import static zhibi.wechat.mp.extra.context.BaseConfig.REQUEST_PREFIX;

@Controller
@RequestMapping(REQUEST_PREFIX + "user")
public class WxMpUserController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 用户列表
     *
     * @param model
     * @param page
     * @param user
     * @return
     */
    @RequestMapping("list")
    public String list(Model model, Page page, User user) {
        Example example = Example.getInstance()
                .addOrder("subscribeTime", ExampleType.OrderType.DESC)
                .addParam("nickname", user.getNickname(), ExampleType.Operation.LIKE)
                .addParam("id", user.getOpenId(), ExampleType.Operation.LIKE);
        PageInfo<User> pageInfo = userService.selectByExample(example, page);
        setModelAttribute(model, pageInfo);
        return VIEW_PREFIX + "user/list";
    }

}
